package com.example.hemin.fnb.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.example.hemin.fnb.R;
import com.example.hemin.fnb.ui.base.BaseMvpActivity;
import com.example.hemin.fnb.ui.util.AppUtils;
import com.example.hemin.fnb.ui.util.ProgressWebView;
import com.example.hemin.fnb.ui.util.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 商品详情界面
 */
public class ShoppingCarItemActivity extends BaseMvpActivity {
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.webview)
    ProgressWebView mWebView;
    //    @BindView(R.id.lay_back)
//    LinearLayout layBack;
//    @BindView(R.id.title)
//    TextView title;
//    @BindView(R.id.xbanner)
//    XBanner xbanner;
//    @BindView(R.id.title1)
//    TextView title1;
//    @BindView(R.id.title2)
//    TextView title2;
//    @BindView(R.id.image)
//    ImageView image;
//    @BindView(R.id.title3)
//    TextView title3;
//    @BindView(R.id.button1)
//    TextView button1;
//    @BindView(R.id.button2)
//    TextView button2;
//    @BindView(R.id.button3)
//    TextView button3;
    private List<String> images = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.shopping_car_item;
    }

    @Override
    public void initView() {
        title.setText("藏品详情");

       String id = Utils.getUserId(this);
       String Authorization = Utils.getAuthorizationHeard(this);
       String url = "http://10.10.10.112:8080/#/web/goods/"+3+"/"+Authorization;
        Log.d("findIntentUrl", url);
        mWebView.loadUrl(url);//加载网址
        mWebView.setFocusable(true);//设置有焦点
        title.setText("玩鉴");
        mWebView.setFocusableInTouchMode(true);//设置可触摸
//        initXBanner();
//        initDate();
    }

//    private void initXBanner() {
//        List<CustomViewsInfo> data = new ArrayList<>();
//        data.add(new CustomViewsInfo("#FFA54F"));
//        data.add(new CustomViewsInfo("#8EE5EE"));
//        data.add(new CustomViewsInfo("#00FA9A"));
//        data.add(new CustomViewsInfo("#CD8162"));
//        xbanner.setBannerData(R.layout.layout_custom_view, data);
//        xbanner.loadImage(new XBanner.XBannerAdapter() {
//            @Override
//            public void loadBanner(XBanner banner, Object model, View view, int position) {
//                TextView tvContent = (TextView) view.findViewById(R.id.tv);
//                tvContent.setText(String.valueOf(position + 1));
//                view.setBackgroundColor(Color.parseColor(((CustomViewsInfo) model).getXBannerUrl()));
//            }
//        });
//        xbanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
//            @Override
//            public void onItemClick(XBanner banner, Object model, View view, int position) {
//                Toast.makeText(ShoppingCarItemActivity.this, "点击了" + position, Toast.LENGTH_SHORT).show();
//            }
//        });
//    }
//
//    private void initDate() {
//
//    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            if (mWebView.canGoBack()) {
                mWebView.goBack(); //goBack()表示返回WebView的上一页面
                return true;
            } else {
                finish();
                return true;
            }

        }
        return false;
    }


    @Override
    protected void onResume() {
        super.onResume();
//        xbanner.startAutoPlay();
    }

    @Override
    protected void onStop() {
        super.onStop();
//        xbanner.stopAutoPlay();
    }

    @OnClick({R.id.lay_back, R.id.button1, R.id.button2, R.id.button3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.lay_back:
                finish();
                break;
            case R.id.button1:
                break;
            case R.id.button2:
                break;
            case R.id.button3:
                Intent intent = new Intent(ShoppingCarItemActivity.this, ShopOrders.class);
                startActivity(intent);
                break;
        }
    }
}
